﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DP.Common;
using CRM.BLL;
using CRM.Entity;
using System.Data;
using DP.Web.UI;

namespace CRM.Web
{
    public partial class about : Common.PageBase
    {
        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
        }

        private T_MARKETDEPARTMENT_BLL marketDepartmentBll = new T_MARKETDEPARTMENT_BLL();
        T_BUSINESSDIVISION_BLL bdBll = new T_BUSINESSDIVISION_BLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ddlMARKETBinding();
            }

        }

        private void ddlMARKETBinding()
        {

            //ddlMARKET.DataSource = bdBll.GetCacheList(this.Page, String.Format(" and Status = {0} ", ((int)Status.启用).ToString()), "Status");
            //ddlMARKET.DataTextField = "BUSINESSDIVISIONNAME";
            //ddlMARKET.DataValueField = "BUSINESSDIVISIONID";
            //ddlMARKET.DataBind();


            var list = marketDepartmentBll.GetList(String.Format(" and Status = {0} ", ((int)Status.启用).ToString()));
            ddlMARKET.DataSource = list;
            ddlMARKET.DataTextField = "MarketDepartmentName";
            ddlMARKET.DataValueField = "MarketDepartmentID";
            ddlMARKET.DataBind();
        }


        protected void ddlMARKET_SelectedIndexChanged(object sender, EventArgs e)
        {
            PageHelper.ShowMessage(this.Page, ddlMARKET.SelectedValue);
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            if(!StringHelper.IsNumber(txtRecord.Text.Trim()))
            {
                return;
            }
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("USERID", Type.GetType("System.Int32"));
            dt.Columns.Add(dc);
            dc = new DataColumn("USERNAME", Type.GetType("System.String"));
            dt.Columns.Add(dc);
            dc = new DataColumn("LOGINNAME", Type.GetType("System.String"));
            dt.Columns.Add(dc);
            DataRow dr;
            int count = StringHelper.ToInt(txtRecord.Text.Trim(), 0);
            for (int i = 0; i < count; i++)
            {
                dr = dt.NewRow();
                dr["USERID"] = i;
                dr["USERNAME"] = "USERNAME" + i.ToString();
                dr["LOGINNAME"] = "LOGINNAME" + i.ToString();
                dt.Rows.Add(dr);
            }



            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("USERID", "用户编号");
            dict.Add("USERNAME", "用户姓名");
            dict.Add("LOGINNAME", "登录名");

            lblMessage.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br />";
            //OpenXMLExcelHelper.DataTableToExcel(dt, dict, "userList.xls");
            NPOIExcelHelper.DataTableToExcel(dt, dict, "userList.xls");
            lblMessage.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br /><br />";
            dt.Clear();
            dt = null;
            GC.Collect();

        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            lblMessage.Text = txtMessage.Text;
        }
    }
}
